<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@include file="/WEB-INF/common/hplus-css.jsp"%>
</head>
<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight" >
	<h4>添加字典</h4>
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox">
					<div class="ibox-content">
						<div style="padding-right: 60px;">
							<form action="${path}/setting/add" class="form-horizontal m-t"id="settingForm" method="post">
								<div class="form-group" style="padding: 0px;">
									<label class="col-sm-2 control-label">名称：</label>
									<div class="col-sm-8">
										<input type="text" id="name" name="name" minlength="2"
											class="form-control" required="" aria-required="true">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">编码：</label>
									<div class="col-sm-8">
										<input type="text" id="code" name="code" minlength="2"
											class="form-control" required="" aria-required="true">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">父级菜单：</label>
									<div class="col-sm-8">
									   <input type="hidden" id="pid" name="pid" value="${parent.id}">
									   <input type="text" id="pname" name="pname"
											class="form-control" required="" readonly aria-required="true" value="${parent.name}">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">字典值：</label>
									<div class="col-sm-8">
										<input type="text" class="form-control" id="val" name="val"
											>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">扣分项：</label>
									<div class="col-sm-8">
										<input type="text" class="form-control" id="integral" name="integral">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">手机版名称：</label>
									<div class="col-sm-8">
										<input type="text" class="form-control" id="sims" name="sims" required="">
									</div>
								</div>
								<div class="form-group">
									<div class="col-sm-8 col-sm-offset-3">
										<button class="btn btn-primary" id="add-btn" type="button">提交</button>
										<button class="btn btn-danger" style="margin-left:30px;" id="return-btn" type="button">关闭</button>
									</div>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<%@include file="/WEB-INF/common/hplus-js.jsp"%>
	<script src="${path}/assets/hplus/js/demo/form-validate-demo.js"></script>
	<script src="${path}/assets/hplus/js/plugins/jsTree/jstree.min.js"></script>
	<script>
	
		$(document).ready(function() {
			// 在键盘按下并释放及提交后验证提交表单
            $("#settingForm").validate({
                  rules: {
                	  name: "required",//项目名
                      code: "required",
                      val:"required",
                     
                      releaseDate: {
                          required: true,
                      },
                  },
                  messages: {
                	  name: "必填",
                      code: "必填",
                      publishContent:"必填",
                    
                      val: {
                          required: "必填",
                      },
                  }, invalidHandler: function(form, validator) {
                      var errors = validator.numberOfInvalids();
                      if (errors) {                    
                          validator.errorList[0].element.focus();
                      }
                  } 
              }) 
			$('.i-checks').iCheck({
				checkboxClass : 'icheckbox_square-green',
				radioClass : 'iradio_square-green',
			});
			$("#return-btn").on("click",function(){
				parent.layer.closeAll();
	  		}); 
			$("#add-btn").click(function() {
				
				var valid = $("#settingForm").valid();
				if (valid) {
					$("#settingForm").ajaxSubmit({
						dataType : "json",
						success : function(json) {
							var code = json.code;
							if (code == 0) {
								layer.msg('添加成功', {
									icon : 1
								});
								setTimeout(function() {
									window.parent.location.href='${path}/setting/query';
									parent.layer.closeAll();
								}, 1000);
							} else {
								layer.msg('添加发生错误:' + json.msg, {
									icon : 5
								});
							}
						},
						error : function() {
							layer.msg('添加发生错误', {
								icon : 5
							});
						}
					});
				}else{
					layer.msg("请填写完整信息！！！！", {
						icon : 5
					});
                }
			});
		});
	</script>
</body>
</html>
